$(document).ready(function(){
	var contextPath = document.location.pathname;
	var index = contextPath.substr(1).indexOf("/");
	contextPath = contextPath.substr(1, index);
	var basePath = "/" + contextPath;
	/**定时器定时重新获取短信验证码*/
	var second = 90;
	var time = 1000;
	var openClose=0;
	var validObject = $("#registerPhone").Validform({
		
		dataType:'text',
		tiptype:2,
		ajaxPost:true,
		
		callback:function(data){
			if(data.flag==0){
        		alert("恭喜您,您的手机号码还没被注册");
        		var memberId = data.memberId;
        		window.location.assign(basePath+"/HRTWEB/jumpToPersonalInfo.do?memberId="+memberId);
        	}
        	
        	
        	else{
        		alert("注册结果：验证码输入错误");
        		
        	}
		},
		
		tiptype:function(msg,o,cssctl){
			
			if(!o.obj.is("form")){
				var tds=o.obj.text();
				
				var objtip=o.obj.siblings(".Validform_checktip");
				cssctl(objtip,o.type);
				objtip.text(msg);
			
				
			}	
			
		}
		
		
	
	});
	
	$(".registerPass").delegate(
			'a',
			'click',
			function(){
				if(openClose == 0){
		           $(".hideOrShowdiv").css("display","block");
		           openClose=1;
				}else{
					$(".hideOrShowdiv").css("display","none");
			        openClose=0;
				}
	});	
	
	
	/**
	 * 获取验证码
	 */
	$("#registerPhone").delegate(
			'#validateBtn',
			'click',
			function(){
				alert("alert------");
				getMobile();
	});	
	
	
	function getMobile(){
		
		var mobile = $("#mobile").val();
		$(".validate").css("display","block");
		$("#validateBtn").css("display","none");
	    var memberId = $("#memberId").val();
	    if(memberId==""||memberId=='undefined'||memberId==null){
	    	memberId = -1;
	    }
	    run();
	    alert("mobile--------->"+mobile);
		alert("memberId--------->"+memberId);
		var saveUrl = "../smsRecord/save.do";
		$.ajax({
					url : saveUrl,
					dataType : 'text',
					type:"POST",
					data : {
						mobile:mobile,
						memberId:memberId
					},
					cache : false,

					success : function(data) {
						if(data=="success"){
							alert("验证码发送成功！！");
						}
					},
					error : function(html) {
						alert("验证码发送失败！！");
						return;
					}
				});

	}
	
	/**定时器*/
	function run(){
		interval = setInterval(fun,time);//去掉引号就对了
		}
	function fun(){
		if(second>=0){
			$("#codeTipeClock").text(second+"秒后重新获取");
			second--;
		}else{
			$("#validateBtn").text("重新获取短信验证码");
			$("#codeTipeClock").text("");
			$("#code").val("");
			$("#validateBtn").css("display","block");
			$(".validate").css("display","none");
			$(".hideOrShowdiv").css("display","none");
			clearTimeout(interval);
			second=90;
			}
	}


	
	$("#registerPhone").delegate('#mobile', 'change', function() {
		validObject.config({
		 ajaxurl:{
		        success:function(data,obj){
		        	if(data.status=="y"){
		        		$("#validateBtn").removeAttr("disabled");
		        	}else{
		        		$("#validateBtn").attr("disabled","true");
		        	}
		        	
		           
		        },
		    	 error:function(data,obj){
			            alert("error:"+data+obj);
			        }
		        
		    }
			
			
		});
	
	});
	
	
	
	
	
	
	
});